OPTIONAL Sprite-animation.f

Requires Structs
Requires FixedPoint
Requires SORA/Spritesets

Only Forth Definitions

Struct
	cell field ->counter
	cell field ->frame#
	cell field ->sprite#
	cell field ->frame
	cell field ->spriteset
	cell field ->speed
End-struct /Sprite-controller

:macro @frame 	->frame @ ;

: frame-addr  ( sprctl -- frame )
	dup ->frame# @ frame[] ;

: animstep  ( sprctl -- )
	>r
	r@ ->counter @  r@ ->speed @ -  dup r@ ->counter !  dup  0< if
		r@ ->frame# @  next-frame  dup -1 > if r@ ->frame# ! 
			r@ frame-addr  r@ ->frame !
			r@ ->frame @  @delay  s>.  r@ ->counter +!
		else drop then
	else
		drop
	then 
	r> drop ;

: sprctl!frame   ( frame# sprctl -- )
	swap over ->frame# !
	dup frame-addr  swap ->frame ! ;

: sprctl!sprite  ( sprite# sprctl -- )
	>r
	r@ ->sprite# !
	r@ ->spriteset @  r@ ->sprite# @  sprite[]  first-frame  r@ ->frame# ! 
	r@ frame-addr  r@ ->frame !
	r@ ->frame @  @delay  s>.  r> ->counter !	;
